package Page.TeacherAndStudentPage;

import Navigation.NavigationController;
import Dao.FullTimeTeacherDao;
import DataClass.FullTimeTeacher;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class FullTimeTeacherPage {
    public static Scene getScene() {
        StackPane fullTimeTeacherMenuPane = new StackPane();
        Label label = new Label("Full-time Menu Page");

        // 创建表格
        TableView<FullTimeTeacher> tableView =  new TableView<>();

        // 创建列
        TableColumn<FullTimeTeacher,String> nameColumn = new TableColumn<>("姓名");
        nameColumn.setCellValueFactory(new PropertyValueFactory<FullTimeTeacher,String>("TCName"));

        TableColumn<FullTimeTeacher,String> titleColumn = new TableColumn<>("职称");
        titleColumn.setCellValueFactory(new PropertyValueFactory<FullTimeTeacher,String>("JTNo"));

        TableColumn<FullTimeTeacher,String> teacherQualificationColumn = new TableColumn<>("导师资格");
        teacherQualificationColumn.setCellValueFactory(new PropertyValueFactory<FullTimeTeacher,String>("TQualification"));

        TableColumn<FullTimeTeacher,String> teacherDutiesColumn = new TableColumn<>("研究所职务");
        teacherDutiesColumn.setCellValueFactory(new PropertyValueFactory<FullTimeTeacher,String>("TDuties"));

        TableColumn<FullTimeTeacher,String> professionalAffiliationsColumn = new TableColumn<>("社会兼职");
        professionalAffiliationsColumn.setCellValueFactory(new PropertyValueFactory<FullTimeTeacher,String>("TProfessionalAffiliations"));

        TableColumn<FullTimeTeacher,String> teacherAdminPositionsCollegeColumn = new TableColumn<>("学院行政职务");
        teacherAdminPositionsCollegeColumn.setCellValueFactory(new PropertyValueFactory<FullTimeTeacher,String>("TAdminPositionsCollege"));
        // 填充列表
        List<TableColumn<FullTimeTeacher, ?>> columns = new ArrayList<>();
        columns.add(nameColumn);
        columns.add(titleColumn);
        columns.add(teacherQualificationColumn);
        columns.add(teacherDutiesColumn);
        columns.add(professionalAffiliationsColumn);
        columns.add(teacherAdminPositionsCollegeColumn);
        tableView.getColumns().addAll(columns);

        // 装入数据
        try {
            List<FullTimeTeacher> data = FullTimeTeacherDao.getFullTimeTeacher();
            tableView.getItems().addAll(data);
        }catch (SQLException ignored)
        {
            System.err.println("数据库出现错误");
        }

        fullTimeTeacherMenuPane.getChildren().add(label);
        fullTimeTeacherMenuPane.getChildren().add(tableView);

        VBox vbox = new VBox();
        Button button = new Button("返回");
        button.setOnAction(event -> {
            NavigationController.back();
        });
        vbox.getChildren().add(button);
        vbox.getChildren().add(fullTimeTeacherMenuPane);
        return new Scene(vbox);
    }
}
